﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataAccess;

namespace QUANLYKHACHSAN_N4
{
    public partial class frmSuDungDichVu : DevComponents.DotNetBar.Office2007RibbonForm
    {
        public frmSuDungDichVu()
        {
            InitializeComponent();
        }
        TaiKhoan_Info tk;
        private void frmSuDungDichVu_Load(object sender, EventArgs e)
        {
            XuLyDataGridView.Style(dgrDanhSach);
            dgrDanhSach.DataSource = Phong_Info.GetDaThue().Tables[0];
            tk = (this.MdiParent as frmFormMain).tk;
        }



     


        private void dgrDichVu_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            try
            {
                string maphieu = dgrDanhSach.CurrentRow.Cells["MAPHIEU"].Value.ToString();
                string madichvu = dgrDichVu.CurrentRow.Cells["DICHVU"].Value.ToString();
                string maphong = dgrDanhSach.CurrentRow.Cells["MAPHONG"].Value.ToString();
                    
                if (e.ColumnIndex == 0)
                {
                    if (DgResul.ShowDiag("Bạn có muốn xóa dịch vụ này", true))
                    {

                        btnXoaDichVu_Click(null, null);
                    }
                }
            }
            catch (Exception)
            {

            }
        }



       
        private void btnTaiLai_Click(object sender, EventArgs e)
        {
            this.OnLoad(null);
        }

      
        private void dgrDanhSach_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            try
            {
                dgrDichVu.DataSource = DichVu_Info.GetByMaPhieuThue(dgrDanhSach.CurrentRow.Cells["MAPHIEU"].Value.ToString()).Tables[0];
            }
            catch (Exception)
            {
            }
        }

        private void btnXoaDichVu_Click(object sender, EventArgs e)
        {
            if (dgrDichVu.SelectedRows.Count == 0)
            {
                DgResul.ShowDiag("Chọn dịch vụ cần xóa sau đó nhân");
                return;
            }
            else
            {
                try
                {
                    string maphieu = dgrDanhSach.CurrentRow.Cells["MAPHIEU"].Value.ToString();
                    string maphong = dgrDanhSach.CurrentRow.Cells["MAPHONG"].Value.ToString();
                    string dichvu = dgrDichVu.CurrentRow.Cells["DICHVU"].Value.ToString();
                    string madv = dgrDichVu.CurrentRow.Cells["MADV"].Value.ToString();

                    if (DgResul.ShowDiag("Bạn có muốn xóa những dịch vụ đã chọn", true))
                    {
                        foreach (DataGridViewRow r in dgrDichVu.SelectedRows)
                        {
                        }
                        DgResul.ShowDiag("Đã xóa xong những dịch vụ được chọn");
                        dgrDanhSach_CellMouseClick(null, null);
                    }
                }
                catch (Exception)
                {
                }

            }
        }

        private void btnThemDichVu_Click(object sender, EventArgs e)
        {
            try
            {
                string maphieu = dgrDanhSach.CurrentRow.Cells["MAPHIEU"].Value.ToString();
                string maphong = dgrDanhSach.CurrentRow.Cells["MAPHONG"].Value.ToString();
                frmThemSuaDichVu frm = new frmThemSuaDichVu(maphieu, maphong);
                frm.ShowDialog();
                if (frm.acction)
                    dgrDanhSach_CellMouseClick(null, null);
            }
            catch (Exception)
            {

            }
        }

        private void btnSuaDichVu_Click(object sender, EventArgs e)
        {
            if (dgrDichVu.SelectedRows.Count == 0)
            {
                DgResul.ShowDiag("Chọn dịch vụ muốn chỉnh sửa và chỉnh sửa");
                return;
            }
            string maphieu = dgrDanhSach.CurrentRow.Cells["MAPHIEU"].Value.ToString();
            string maphong = dgrDanhSach.CurrentRow.Cells["MAPHONG"].Value.ToString();
            string dichvu = dgrDichVu.CurrentRow.Cells["DICHVU"].Value.ToString();
            string madv = dgrDichVu.CurrentRow.Cells["MADV"].Value.ToString();
            string soluong = dgrDichVu.CurrentRow.Cells["SOLUONG"].Value.ToString();
            frmThemSuaDichVu frm = new frmThemSuaDichVu(maphieu, maphong, madv, dichvu, soluong);
            frm.ShowDialog();
            if (frm.acction)
                dgrDanhSach_CellMouseClick(null, null);
        }

        private void btnThuePhong_Click(object sender, EventArgs e)
        {
            frmFormMain frm2 = MdiParent as frmFormMain;
            frmThuePhong frm = new frmThuePhong(frm2.tk);
            frm.ShowDialog();
            this.OnLoad(null);
        }

        private void btnInAn_Click(object sender, EventArgs e)
        {
            string maphieu = dgrDanhSach.CurrentRow.Cells["MAPHIEU"].Value.ToString();
            string maphong = dgrDanhSach.CurrentRow.Cells["MAPHONG"].Value.ToString();
            string khachhang = dgrDanhSach.CurrentRow.Cells["KHACHHANG"].Value.ToString();
            string maloai = dgrDanhSach.CurrentRow.Cells["LOAIPHONG"].Value.ToString();
            DateTime ngaydi = DateTime.Parse(dgrDanhSach.CurrentRow.Cells["NGAYDI"].Value.ToString());
            DateTime ngayden = DateTime.Parse(dgrDanhSach.CurrentRow.Cells["NGAYDEN"].Value.ToString());
            double ngaythang = (ngaydi - ngayden).TotalDays;

            frmChiTietHoaDon frm = new frmChiTietHoaDon(maphong,maphieu,khachhang,maloai,ngaythang);
            frm.ShowDialog();
        }
    }
}
